using MicroMsg.Storage;
using System;
namespace MicroMsg.Manager
{
	public class ConfigMgr : IStorageLogin
	{
		private static StorageKeyValue storageKeyValue_0 = new StorageKeyValue(new Func<string>(StorageIO.getConfigPath));
		private static ConfigMgr instance = new ConfigMgr();
		public static void init()
		{
			StorageBasic.registerLoginNotify(ConfigMgr.instance);
		}
		public void onLogin(string userName)
		{
			ConfigMgr.storageKeyValue_0.checkEmpty();
			ConfigMgr.storageKeyValue_0.releaseAll(false);
			if (!ConfigMgr.storageKeyValue_0.exist<CommanConfig>() && AccountMgr.getCurAccount().nVersion <= 1627521281)
			{
				ConfigMgr.setBool("bIsEnabledAddrBookMatch", AccountMgr.getCurAccount().bIsEnabledAddrBookMatch);
				ConfigMgr.setBool("bNotFirstInLbs", AccountMgr.getCurAccount().bNotFirstInLbs);
				ConfigMgr.setBool("bNotShowDialogInLbs", AccountMgr.getCurAccount().bNotShowDialogInLbs);
				ConfigMgr.setBool("bHasAskOpenPush", AccountMgr.getCurAccount().bHasAskOpenPush);
				ConfigMgr.setInt("nMainPageSelectedIndex", AccountMgr.getCurAccount().nMainPageSelectedIndex);
			}
		}
		public virtual void onLogout()
		{
			ConfigMgr.storageKeyValue_0.releaseAll(true);
		}
		private static bool check()
		{
			return AccountMgr.isLogin;
		}
		public static T smethod_0<T>() where T : class
		{
			if (!ConfigMgr.check())
			{
				return default(T);
			}
			return ConfigMgr.storageKeyValue_0.method_0<T>();
		}
		public static bool save<T>(bool saveAndRemoveCache = false) where T : class
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.save<T>(saveAndRemoveCache);
		}
		public static T read<T>() where T : class
		{
			if (!ConfigMgr.check())
			{
				return default(T);
			}
			return ConfigMgr.storageKeyValue_0.read<T>();
		}
		public static bool write<T>(T data) where T : class
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.write<T>(data);
		}
		public static bool delayWrite<T>(T data) where T : class
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.delayWrite<T>(data);
		}
		public static void delete<T>() where T : class
		{
			if (!ConfigMgr.check())
			{
				return;
			}
			ConfigMgr.storageKeyValue_0.delete<T>();
		}
		public static bool delValue(string key_name)
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.delValue(key_name);
		}
		public static int getInt(string key_name, int default_value = 0)
		{
			if (!ConfigMgr.check())
			{
				return default_value;
			}
			return ConfigMgr.storageKeyValue_0.getValue<int>(key_name, default_value);
		}
		public static bool setInt(string key_name, int value)
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.setValue<int>(key_name, value);
		}
		public static ulong getUlong(string key_name, ulong default_value = 0uL)
		{
			if (!ConfigMgr.check())
			{
				return default_value;
			}
			return ConfigMgr.storageKeyValue_0.getValue<ulong>(key_name, default_value);
		}
		public static bool setUlong(string key_name, ulong value)
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.setValue<ulong>(key_name, value);
		}
		public static double getDouble(string key_name, double default_value = 0.0)
		{
			if (!ConfigMgr.check())
			{
				return default_value;
			}
			return ConfigMgr.storageKeyValue_0.getValue<double>(key_name, default_value);
		}
		public static bool setDouble(string key_name, double value)
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.setValue<double>(key_name, value);
		}
		public static string getString(string key_name, string default_value = "")
		{
			if (!ConfigMgr.check())
			{
				return default_value;
			}
			return ConfigMgr.storageKeyValue_0.getValue<string>(key_name, default_value);
		}
		public static bool setString(string key_name, string value)
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.setValue<string>(key_name, value);
		}
		public static bool getBool(string key_name, bool default_value = false)
		{
			if (!ConfigMgr.check())
			{
				return default_value;
			}
			return ConfigMgr.storageKeyValue_0.getValue<bool>(key_name, default_value);
		}
		public static bool setBool(string key_name, bool value)
		{
			return ConfigMgr.check() && ConfigMgr.storageKeyValue_0.setValue<bool>(key_name, value);
		}
		public static void test()
		{
			ConfigMgr.getInt("test int", 0);
			ConfigMgr.getDouble("test double", 0.0);
			ConfigMgr.getString("test string", "");
			ConfigMgr.getBool("test bool", false);
			ConfigMgr.getBool("test int", false);
			ConfigMgr.setInt("test int", 111);
			ConfigMgr.setDouble("test double", 222.0);
			ConfigMgr.setString("test string", "333");
			ConfigMgr.setBool("test bool", true);
		}
	}
}
